//
//  WalletWithDrawMoneyViewController.m
//  BGM
//
//  Created by 我要变好看 on 2019/1/6.
//  Copyright © 2019 com.alirtc.demo. All rights reserved.
//

#import "WalletWithDrawMoneyViewController.h"

#import "Common.h"
#import "BGMUser.h"
#import "BGMHTTP.h"

#import "SVProgressHUD.h"
@interface WalletWithDrawMoneyViewController ()

@property(nonatomic, strong)UITextField *payText;
@end

@implementation WalletWithDrawMoneyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navview.hidden = NO;
    self.titleBtn.hidden = NO;
    [self.titleBtn setTitle:@"提现" forState:UIControlStateNormal];
    
    
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(20, self.navview.frame.size.height+30, SCREENW-40, 290)];
    bgView.backgroundColor = [UIColor whiteColor];
    bgView.layer.borderColor = [UIColor grayColor].CGColor;
    bgView.layer.borderWidth = 0.1;
    bgView.layer.masksToBounds = YES;
    bgView.layer.cornerRadius = 8;
    [self.view addSubview:bgView];
    
    
    UILabel *lable1 = [[UILabel alloc]initWithFrame:CGRectMake(20, 20, 100, 20)];
    lable1.text = @"到账支付宝";
    lable1.textColor = bgmmainColor;
    lable1.font = [UIFont systemFontOfSize:15];
    [bgView addSubview:lable1];
    
    
    
    UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(130, 20, 25, 20)];
    [imageView setImage:[UIImage imageNamed:@"payicon"]];
    [bgView addSubview:imageView];
    
    UILabel *iphoneNumber = [[UILabel alloc]initWithFrame:CGRectMake(imageView.frame.origin.x+imageView.frame.size.width, imageView.frame.origin.y, 100, 20)];
    iphoneNumber.text = @"18667115667";
    iphoneNumber.textColor = bgmyelloeColor;
    iphoneNumber.font = [UIFont systemFontOfSize:15];
    [bgView addSubview:iphoneNumber];

    UILabel *text = [[UILabel alloc]initWithFrame:CGRectMake(imageView.frame.origin.x+imageView.frame.size.width, iphoneNumber.frame.origin.y+iphoneNumber.frame.size.height, 100, 40)];
    text.text = @"24小时内到账";
    text.textColor = bgmsmallColor;
    text.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:text];
    
    
    
    UILabel *line = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, bgView.frame.size.width, 0.3)];
    line.backgroundColor = [UIColor grayColor];
    line.alpha = 0.2;
    [bgView addSubview:line];
    

    UILabel *lable2 = [[UILabel alloc]initWithFrame:CGRectMake(20, line.frame.origin.y+15, 100, 20)];
    lable2.text = @"提现金额";
    lable2.textColor = bgmmainColor;
    lable2.font = [UIFont systemFontOfSize:15];
    [bgView addSubview:lable2];
    
    UILabel *line1 = [[UILabel alloc]initWithFrame:CGRectMake(0, 80, bgView.frame.size.width, 0.3)];
    line1.backgroundColor = [UIColor grayColor];
    line1.alpha = 0.2;
    [bgView addSubview:line1];
    
    
    
    UILabel *line2 = [[UILabel alloc]initWithFrame:CGRectMake(15, line1.frame.origin.y+50, 30, 50)];
    line2.text = @"￥";
    line2.textColor = bgmmainColor;
    line2.font = [UIFont systemFontOfSize:30];
    [bgView addSubview:line2];
    
    self.payText = [[UITextField alloc]initWithFrame:CGRectMake(50, line1.frame.origin.y+50, 200, 50)];
    self.payText.keyboardType = UIKeyboardTypeDecimalPad;
    self.payText.returnKeyType = UIReturnKeyDone;
    self.payText.placeholder = @"输入金额";
    self.payText.font =[UIFont systemFontOfSize:20];
    [bgView addSubview:self.payText];
    
    UILabel *line3 = [[UILabel alloc]initWithFrame:CGRectMake(15, self.payText.frame.origin.y+self.payText.frame.size.height, bgView.frame.size.width-30, 0.3)];
    line3.backgroundColor = [UIColor grayColor];
    line3.alpha = 0.2;
    [bgView addSubview:line3];
    
    
    UILabel *line5 = [[UILabel alloc]initWithFrame:CGRectMake(15, line3.frame.origin.y+line3.frame.size.height+8, 130, 20)];
    line5.text = [NSString stringWithFormat:@"本次可提现   ￥%.2f",[self.money floatValue]];
    line5.textColor = bgmsmallColor;
    line5.font = [UIFont systemFontOfSize:13];
    [bgView addSubview:line5];
    
    
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(line5.frame.origin.x+line5.frame.size.width+10, line5.frame.origin.y, 60,20)];
    [btn setTitle:@"全部提现" forState:UIControlStateNormal];
    [btn setTitleColor:bgmyelloeColor forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:13];
    [bgView addSubview:btn];
    [btn addTarget:self action:@selector(clickAll) forControlEvents:UIControlEventTouchUpInside];
    
    
    
    UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(15, line5.frame.origin.y+line5.frame.size.height+10, bgView.frame.size.width-40,45)];
    btn1.backgroundColor = bgmyelloeColor;
    [btn1 setTitle:@"提现" forState:UIControlStateNormal];
    [btn1 setTitleColor:bgmmainColor forState:UIControlStateNormal];
    btn1.layer.cornerRadius = 8;
    btn1.layer.masksToBounds = YES;
    btn1.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn1 addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
    [bgView addSubview:btn1];
    
}

- (void)clickBtn{    
    if ([self.payText.text floatValue]>[self.money floatValue]) {
        [SVProgressHUD showInfoWithStatus:@"有多少钱，取多少钱"];
        return;
    }else if ([self.payText.text floatValue]<20){
        [SVProgressHUD showInfoWithStatus:@"最少取20元"];
        return;
    }
    
    [SVProgressHUD showWithStatus:@"支付宝会收取0.6%手续费用"];
    
    NSDictionary *params = @{@"userToken":[BGMUser shareInstance].userToken,@"userId":[BGMUser shareInstance].userId,@"smsCode":self.smsCode,@"money": self.payText.text};
    [BGMHTTP requestWithMethodName:@"users/cashWithdrawal" parameters:params completion:^(BOOL success, NSError *error, NSDictionary *result) {
        NSString *code = [NSString stringWithFormat:@"%@",[result objectForKey:@"code"]];
        if ([code isEqualToString:@"200"]) {
            [SVProgressHUD showSuccessWithStatus:@"提现成功"];
            [self successCash];
        }
    }];
    
}

- (void)clickAll{
    self.payText.text = self.money ;
}


-(void)successCash{
    [[NSNotificationCenter defaultCenter]postNotificationName:@"freshUserMoenyNotification" object:nil];
    
    NSArray *array = self.navigationController.viewControllers;
    [self.navigationController popToViewController:[array objectAtIndex:1] animated:YES];
}


@end


